package mvc.struts.annotation.web;

import java.util.Map;

import mvc.struts.annotation.action.Controller;
import mvc.struts.annotation.action.RequestMapping;
import mvc.struts.annotation.entity.LoginVO;
import mvc.struts.annotation.entity.Param;
import mvc.struts.annotation.entity.View;

@Controller
public class LoginController {

	/**
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/myservlet/login", method="GET")
	public String onLogin(Param param)
	{
		return	"onLogin";
	}
	
	/**
	 * 
	 * @param param
	 * @return
	 */
	@RequestMapping(value = "/myservlet/mylogin", method="GET")
	public View onMyLogin(Param param)
	{
		LoginVO	loginVo = new LoginVO();
		loginVo.setName("Mark");
		loginVo.setPassword("4533d");
		
		View	view = new View("Login");
		
		view.addModel("loginVo", loginVo);
		
		return	view;
	}
	
	/**
	 * 
	 * @param param
	 * @return
	 */
	@RequestMapping(value = "/myservlet/loginjudge", method="GET")
	public View onMyLoginJudge(Param param)
	{
		View	view;
		
		Map<String, Object>	paramMap = param.getMap();
		
		String	name     = (String)paramMap.get("name");
		String	password = (String)paramMap.get("password");
		
		if	(name.equals("usw") && password.equals("usw12345"))
		{
			view = new View("Success");
		}
		else
		{
			view = new View("Failure");
		}
		
		return	view;
	}
	
	/**
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/myservlet/loginout", method="GET")
	public String onLoginOut(Param param)
	{
		return	"onLoginOut";
	}	
}
